Skip to content

Encapsulate Advisor Parameters with ChatMemoryAdvisorOptions #2601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

dev-jonghoonpark
Copy link
Contributor

Changes

This PR introduces the ChatMemoryAdvisorOptions class to encapsulate advisor parameters.

Background

Previously, CHAT_MEMORY_CONVERSATION_ID_KEY and CHAT_MEMORY_RETRIEVE_SIZE_KEY had to be referenced directly:

import static org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY;
import static org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor.CHAT_MEMORY_RETRIEVE_SIZE_KEY;

// ...

this.chatClient.prompt()
        .user(userMessageContent)
        .advisors(a -> a
                .param(CHAT_MEMORY_CONVERSATION_ID_KEY, chatId)
                .param(CHAT_MEMORY_RETRIEVE_SIZE_KEY, 100))
        .stream().content();

Improvements

By introducing ChatMemoryAdvisorOptions, the code is now more structured:

ChatMemoryAdvisorOptions options = ChatMemoryAdvisorOptions.builder()
        .conversationId(chatId)
        .retrieveSize(100)
        .build();

return this.chatClient.prompt()
        .user(userMessageContent)
        .advisors(options::applyTo)
        .stream().content();

@ThomasVitale
Copy link
Contributor

@dev-jonghoonpark thanks so much for your contribution! We've been working to improve the chat memory support in Spring AI.

We have just delivered some changes to the ChatMemory API which include the introduction of a ChatMemoryRepository API to separate the two different concerns: memory management strategy and storage mechanism. New documentation: https://docs.spring.io/spring-ai/reference/api/chat-memory.html and upgrade notes: https://docs.spring.io/spring-ai/reference/upgrade-notes.html#_chat_memory.

After 1.0.0 is out, we're planning to continue the improvement work by making chat memory a first-class citizen in ChatClient, so that it's possible to pass both ChatMemory and conversationId directly to ChatClient, instead of handling it all outside via Advisors. Some early ideas can be seen in #2803, but the whole feature will require more design work. We hope to have it done right after the 1.0.0 GA release.

My suggestion would be to wait for that new design to have memory support built into ChatClient directly.

@dev-jonghoonpark
Copy link
Contributor Author

Based on the comments, close this PR.
I'm Looking forward to the new design.
Thank you.

@dev-jonghoonpark dev-jonghoonpark deleted the encapsulated-chat-memory-advisor-parameters branch April 27, 2025 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants